/*
 *  Initiative.h
 *  initiativeTracker
 *
 *  Created by Sam Jaffe on 5/9/12.
 *  Copyright 2012 WPI. All rights reserved.
 *
 */

#pragma once

#include <string>
#include <vector>
#include <memory>
#include <xercesc/dom/DOMNode.hpp>
#include "Character.h"
#include "Trap.h"
#include "CharGen.h"

class InitTracker {
private:
    unsigned short turn;
    unsigned short next;
    std::string campaignID;
    
    std::vector<std::shared_ptr<Character>> charList;
    CharGen* generator;
        
public:
    InitTracker();
    InitTracker(unsigned short turn, unsigned short next);
    InitTracker(std::string idn);
    InitTracker(std::string campaignID, unsigned short turn,
                unsigned short next);
    ~InitTracker();
    
    unsigned short getTurn() const;
    unsigned short getNext() const;
    
    unsigned short nextTurn();
    void reset();
    
    std::shared_ptr<Character> get() const;
    std::shared_ptr<Character> get(const int index) const;
    std::shared_ptr<Character> lookup(const int idn) const;
    const int size() const;
    void add(std::shared_ptr<Character> c);
    void add(std::shared_ptr<Character> c, int index);
    void insert(std::shared_ptr<Character> c);
    std::vector<std::shared_ptr<Character>>::const_iterator lookup_it(const int idn) const;
    std::vector<std::shared_ptr<Character>>::iterator lookup_it(const int idn);
    std::vector<std::shared_ptr<Character>>::const_iterator begin() const;
    std::vector<std::shared_ptr<Character>>::const_iterator end() const;
    std::vector<std::shared_ptr<Character>>::iterator begin();
    std::vector<std::shared_ptr<Character>>::iterator end();
    
    void decode(xercesc::DOMNode* node);
    
    const bool initialize(const std::string idn,
                          unsigned const short turnNum,
                          unsigned const short turnNext);
    
    const bool damage(const int idn, const int damage, const bool temp);
    const bool checkHealth(std::shared_ptr<Character> c, const int damage);
    void kill(const int idn);
    void clear(const bool npc_only);
    
    void delay();
    bool changeTurn();
    std::vector<std::shared_ptr<Trap>> checkTraps();
};

inline unsigned short InitTracker::getTurn() const {return turn;}
inline unsigned short InitTracker::getNext() const {return next;}
